package com.admin.his.config;

import java.util.Properties;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

@Configuration
public class BeanValidationConfigration {

	@Bean
	public LocalValidatorFactoryBean validatorFactory() {
		LocalValidatorFactoryBean bean=new LocalValidatorFactoryBean();
		bean.setProviderClass(HibernateValidator.class);
		
		bean.setValidationMessageSource(new ResourceBundleMessageSource() {{
			setBasename("validateMessage");
			setDefaultEncoding("utf-8");
		}});
		
		bean.setValidationProperties(new Properties() {{
			//快速失败
			setProperty("hibernate.validator.fail_fast", "true");
			//是否允许实现类或子类重新定义方法参数约束
			setProperty("hibernate.validator.allow_parameter_constraint_override", "true");
		}});
		
		
		return bean;
	}
}
